<template>
    <div>
      <table class="table">
        <tbody>
           <tr>
            <td>门店名</td>
            <td><input type="text" v-model="data.userName"></td>
           </tr>
           <tr>
            <td>所在地区</td>
            <td>
                <select v-model="data.hoteId">
                    <option value="0">请选择</option>
                    <option v-for="a in datas":value="a.hoteId">{{a.hoteAddress}}</option>
                </select>
            </td>
           </tr>
           <tr>
            <td>门店店长名</td>
            <td><input type="text" v-model="data.userDian"></td>
           </tr>
           <tr>
            <td>店长手机号</td>
            <td><input type="text" v-model="data.userPhone"></td>
           </tr>
           <tr>
            <td>门店成立日期</td>
            <td><input type="date" v-model="data.userTime"></td>
           </tr>
           <tr>
            <td>同时接待最大人数</td>
            <td><input type="text" v-model="data.userZuida"></td>
           </tr>
           <tr>
            <td>门店状态</td>
            <td>
              <input type="radio" name="zt" value="1"  v-model="data.userZhuang">休息
              <input type="radio" name="zt" value="2"  v-model="data.userZhuang">营业
              <input type="radio" name="zt" value="3"  v-model="data.userZhuang">歇业
            </td>
           </tr>
           <tr>
            <td>是否已开业</td>
            <td><input type="text" v-model="data.userKaiye"></td>
           </tr>
           <tr>
            <td></td>
            <td><input type="button" value="添加" @click="postdata"></td>
           </tr>
        </tbody>
      </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { ref ,onMounted} from 'vue';
import { useRouter } from 'vue-router';

const router = useRouter()

const datas = ref([{
    "hoteId": 1,
    "hoteAddress": "月之国"
  }])

onMounted(()=>{
xiala()
})

const xiala=()=>{
  axios.get("/api/Xiala/Xiala").then(res=>{
    datas.value = res.data
  })
}

const data = ref({
  "userId": 0,
  "userName": "",
  "hoteId": 0,
  "userDian": "",
  "userPhone": "",
  "userTime": "2025-05-27T01:58:18.321Z",
  "userZuida": 0,
  "userZhuang": 0,
  "userTimes": "2025-05-27T01:58:18.321Z",
  "userKaiye": 0
})

const postdata=()=>{
if(data.value.userName=="")
{
alert("店名不能为空")
return
}
if(data.value.hoteId==0)
{
alert("下拉框不能为空")
return
}

let pl = /^13\d{9}$/;
if(!pl.test(data.value.userPhone))
{
alert("手机号不符合规定")
return
}



axios.post("/api/USer/AddAsync",data.value).then(res=>{
if(res.data>0)
{
alert("添加成功")
router.push('/List')
}
else
{
alert("添加失败")
}
})
}

</script>

<style scoped>

</style>